package com.big.common.core.exception;

import com.big.common.core.result.IResultCode;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import java.io.Serial;

/**
 * <p>
 * 自定义异常
 * </p>
 *
 * @author 山归岿
 * @create 2025-06-21-16:31
 */
@Slf4j
@Getter
public class CustomerException extends RuntimeException {
    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 错误码
     */
    private int code;

    /**
     * 错误消息
     */
    private final String msg;

    public CustomerException(String msg) {
        super(msg);
        this.msg = msg;
    }

    public CustomerException(IResultCode resultCode) {
        super(resultCode.getMessage());
        this.code = resultCode.getCode();
        this.msg = resultCode.getMessage();
    }

    public CustomerException(IResultCode resultCode, String msg) {
        super(msg);
        this.code = resultCode.getCode();
        this.msg = msg;
    }

    public CustomerException(IResultCode resultCode, Throwable cause) {
        super(cause);
        this.code = resultCode.getCode();
        this.msg = resultCode.getMessage();
    }

    public CustomerException(int code, String msg) {
        super(msg);
        this.code = code;
        this.msg = msg;
    }

}